package com.hyphenate.helpdesk.easeui.widget.chatrow;


import android.content.Context;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hyphenate.chat.Message;
import com.hyphenate.helpdesk.R;
import com.hyphenate.helpdesk.easeui.Constant;
import com.hyphenate.helpdesk.easeui.UIProvider;
import com.hyphenate.helpdesk.easeui.emojicon.Emojicon;
import com.simga.library.utils.glide.GlideUtil;

/**
 * 大表情(动态表情)
 *
 */
public class ChatRowBigExpression extends ChatRowText {

    private ImageView imageView;


    public ChatRowBigExpression(Context context, Message message, int position, BaseAdapter adapter) {
        super(context, message, position, adapter);
    }

    @Override
    protected void onInflatView() {
        inflater.inflate(message.direct() == Message.Direct.RECEIVE ?
                R.layout.hd_row_received_bigexpression : R.layout.hd_row_sent_bigexpression, this);
    }

    @Override
    protected void onFindViewById() {
        percentageView = (TextView) findViewById(R.id.percentage);
        imageView = (ImageView) findViewById(R.id.image);
    }


    @Override
    public void onSetUpView() {
        String emojiconId = message.getStringAttribute(Constant.MESSAGE_ATTR_EXPRESSION_ID, null);
        Emojicon emojicon = null;
        if(UIProvider.getInstance().getEmojiconInfoProvider() != null){
            emojicon =  UIProvider.getInstance().getEmojiconInfoProvider().getEmojiconInfo(emojiconId);
        }
        if(emojicon != null){
            if(emojicon.getBigIcon() != 0){
                GlideUtil.loadPicture(emojicon.getBigIcon(),imageView,R.drawable.hd_default_expression);
            }else if(emojicon.getBigIconPath() != null){
                GlideUtil.loadPicture(emojicon.getBigIconPath(),imageView,R.drawable.hd_default_expression);
            }else{
                imageView.setImageResource(R.drawable.hd_default_expression);
            }
        }

        handleTextMessage();
    }
}